package com.ruoyi.web.controller.wx;

import cn.hutool.json.JSONUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.TabChatMsg;
import com.ruoyi.system.service.ITabChatMsgService;
import com.ruoyi.system.service.impl.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.MessageFormat;

/**
 * @Author：zhanghao
 * @name：WxMsgController
 * @Date：2024/7/4 18:23
 */

@RestController()
@RequestMapping("/wx")
public class WxMsgController extends BaseController {


    @Autowired
    private ITabChatMsgService tabChatMsgService;
    @Autowired
    private RedisService redisService;

    private String wxdlk = "wx:msg";


    @PostMapping("/msg")
    public R<Object> msg(@RequestBody TabChatMsg msg) {
        logger.info("进入微信消息{}", msg.toString());
//        tabChatMsgService.insertTabChatMsg(msg);
        redisService.lPush(wxdlk, JSONUtil.toJsonStr(msg));

        return R.ok();
    }

    private String MESSAGE_KEY = "message:queue";

    @PostMapping("/redis/test/set")
    public R<Object> testset(String k, String v) {
        String[] karr = v.split(",");
        for (String s : karr) {
            redisService.lPush(k, s);
        }
        return R.ok();
    }

    @PostMapping("/redis/test/get")
    public R<Object> testget(String k) {
        String str = (String) redisService.rPop(k);
        System.out.println(MessageFormat.format("redis队列，k={0},v={1}", k, str));
        return R.ok(str);
    }

}
